


class BaseController  {

    constructor(req, res, nunjucks) {

        this.req = req;
        this.res = res;
        this.nunjucks = nunjucks;
        this.nunjucks.configure('./home/html', { autoescape: true });//配置模板的目录

    }

    setSession(key, val) {
        this.res.session[key] = val;
    }

    getSession(key) {
        //console.log(this.req.session);
        return this.req.session[key];
    }

    setCookie(key, val, expries) {
        this.res.setHeader('Set-Cookie', key + "=" + val + "; expries:" + expries);
    }

    getCookie(key) {
        //console.log('cookie json');
        //console.log(this.req.cookie);
        return this.req.cookie[key];
    }


    display(path, data) {
        return this.nunjucks.render(path, data);
    }


}

module.exports = BaseController;